{layout name="layout/header" /}
<link href="root/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<link href="root/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>

<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{$title}</h5>
                    <div class="ibox-tools">
                        <a type="button" class="btn btn-primary btn-sm" href="{:url('index')}">返回列表页</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">标题</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="title" name="title">

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">简介</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="des" name="des">

                            </div>
                        </div>
                        <!--图片上传-->
                        <div class="form-group">
                            <label class="col-sm-1 control-label">封面图</label>
                            <div class="col-sm-10">
                                <button class="btn btn-success product_upload_img" type="button">
                                    <i class="fa fa-upload"></i>&nbsp;&nbsp;<span class="bold">上传</span>
                                </button>
                                <input class="vue_img" type="file" style="display: none;" data-field="img"/>
                            </div>
                            <div class="col-sm-11 col-sm-offset-1 ">
                                <div class="row" id="img">
                                    <div class="img_box col-xs-12 col-md-3" v-if="img!=''">
                                        <a class="fancybox" :href="img">
                                            <img alt="image" :src="img"/>
                                        </a>
                                        <a class="glyphicon glyphicon-trash" onclick="del_wx_img(this,'img');"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--图片上传结束-->
                        <div class="form-group">
                            <label class="col-sm-1 control-label">排序</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="sort" name="sort">
                                <span class="help-block m-b-none">默认0按时间倒序排序，如果大于0，则按数字大小倒序置顶</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">状态</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="display" value="1" name="display"> <i></i>正常</label>
                                    <label><input type="radio" v-model="display" value="0" name="display"> <i></i>关闭</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">详情</label>
                            <div class="col-sm-11">
                                <textarea name="info" id="info" style="display: none" v-model="info"></textarea>
                                <div class="ibox-content no-padding" >
                                    <div class="summernote" v-html="info" data-field="info">

                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-primary" @click="submit" type="submit">保存内容</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<!--layer-->
<script src="root/js/plugins/layer/layer.min.js"></script>
<script src="root/js/plugins/fancybox/jquery.fancybox.js"></script>

<script src="root/js/plugins/summernote/summernote.min.js"></script>
<script src="root/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>
<script>
    var data = {$data};
    var url = "{$url}";
    if(data==1){
        data = {
            'id':0,
            'title':'',
            'info':'',
            'display':1,
            'des':'',
            'img':'',
            'sort':0
        }
    }
    new Vue({
        el:"#app",
        data:data,
        methods:{
            submit:function () {
                $("#form").validate({
                    rules:{
                        title:{
                            required:true,
                        },
                        info:{
                            required:true,
                        },
                        type:{
                            required:true,
                        },
                        sort:{
                            digits:true,
                        }
                    },
                    messages:{
                        type:{
                            required:'请选择分类',
                        }
                    }
                })
                if($("#form").valid()) {
                    $.post(url,data,function (res) {
                        layer.msg(res.msg);

                        if(res.code==1){
                            setTimeout(function () {
                                window.location.href= "{:url('index')}"
                            },1500)
                        }
                    },'json')
                }

            }
        },
        mounted:function () {
            checks();
            $('.summernote').summernote({
                lang:'zh-CN',
                // 重写图片上传
                onImageUpload: function(files, editor, $editable) {
                    sendFile(files[0],editor,$editable);
                },
                onblur:function () {
                    var field = $(this).parent().prev().attr('data-field')
                    data[field] = $(this).code();
                }
            });
        }
    });
</script>

<script>
    $('input[name="display"]').on('ifChecked', function(event){
        data.display = $(this).val()
    });


</script>
